from PyQt5.Qt import *


"""
使用一张遮罩层图片来控制窗口大小，然后利用paintEvent函数重绘窗口的背景图

setMask(self, QBitmap)
为调节它的控件增加一个遮罩层

paintEvent(self, QPaintEvent)
通过重载绘制窗口背景

"""
class MyQWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()

    def setup_ui(self):
        self.setWindowTitle("不规则窗口")
        self.pix = QBitmap("./image/mask.png")
        self.resize(self.pix.size())
        self.setMask(self.pix)

    def paintEvent(self, QPaintEvent):
        painter = QPainter(self)
        painter.drawPixmap(0, 0, self.pix.width(), self.pix.height(), QPixmap(r"./image/screen1.jpg"))

# 测试
if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    window = MyQWidget()
    window.show()
    sys.exit(app.exec_())